{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "import subprocess\n",
    "output = subprocess.check_output(['busctl', 'introspect', '--user', '--xml-interface', 'com.deepin.dde.Dock', '/com/deepin/dde/Dock']).decode()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n",
      "\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n",
      "<node>\n",
      "  <interface name=\"com.deepin.dde.Dock\">\n",
      "    <property name=\"uid\" type=\"i\" access=\"read\"/>\n",
      "    <signal name=\"geometryChanged\">\n",
      "      <arg name=\"geometry\" type=\"(iiii)\" direction=\"out\"/>\n",
      "      <annotation name=\"org.qtproject.QtDBus.QtTypeName.Out0\" value=\"QRect\"/>\n",
      "    </signal>\n",
      "    <method name=\"geometry\">\n",
      "      <arg type=\"(iiii)\" direction=\"out\"/>\n",
      "      <annotation name=\"org.qtproject.QtDBus.QtTypeName.Out0\" value=\"QRect\"/>\n",
      "    </method>\n",
      "    <method name=\"uid\">\n",
      "      <arg type=\"i\" direction=\"out\"/>\n",
      "    </method>\n",
      "  </interface>\n",
      "  <interface name=\"org.freedesktop.DBus.Properties\">\n",
      "    <method name=\"Get\">\n",
      "      <arg name=\"interface_name\" type=\"s\" direction=\"in\"/>\n",
      "      <arg name=\"property_name\" type=\"s\" direction=\"in\"/>\n",
      "      <arg name=\"value\" type=\"v\" direction=\"out\"/>\n",
      "    </method>\n",
      "    <method name=\"Set\">\n",
      "      <arg name=\"interface_name\" type=\"s\" direction=\"in\"/>\n",
      "      <arg name=\"property_name\" type=\"s\" direction=\"in\"/>\n",
      "      <arg name=\"value\" type=\"v\" direction=\"in\"/>\n",
      "    </method>\n",
      "    <method name=\"GetAll\">\n",
      "      <arg name=\"interface_name\" type=\"s\" direction=\"in\"/>\n",
      "      <arg name=\"values\" type=\"a{sv}\" direction=\"out\"/>\n",
      "      <annotation name=\"org.qtproject.QtDBus.QtTypeName.Out0\" value=\"QVariantMap\"/>\n",
      "    </method>\n",
      "    <signal name=\"PropertiesChanged\">\n",
      "      <arg name=\"interface_name\" type=\"s\" direction=\"out\"/>\n",
      "      <arg name=\"changed_properties\" type=\"a{sv}\" direction=\"out\"/>\n",
      "      <annotation name=\"org.qtproject.QtDBus.QtTypeName.Out1\" value=\"QVariantMap\"/>\n",
      "      <arg name=\"invalidated_properties\" type=\"as\" direction=\"out\"/>\n",
      "    </signal>\n",
      "  </interface>\n",
      "  <interface name=\"org.freedesktop.DBus.Introspectable\">\n",
      "    <method name=\"Introspect\">\n",
      "      <arg name=\"xml_data\" type=\"s\" direction=\"out\"/>\n",
      "    </method>\n",
      "  </interface>\n",
      "  <interface name=\"org.freedesktop.DBus.Peer\">\n",
      "    <method name=\"Ping\"/>\n",
      "    <method name=\"GetMachineId\">\n",
      "      <arg name=\"machine_uuid\" type=\"s\" direction=\"out\"/>\n",
      "    </method>\n",
      "  </interface>\n",
      "  <node name=\"Indicator\"/>\n",
      "</node>\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print(output)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'output' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[1], line 3\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mxml\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01metree\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mElementTree\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01met\u001b[39;00m\n\u001b[0;32m----> 3\u001b[0m root \u001b[38;5;241m=\u001b[39m et\u001b[38;5;241m.\u001b[39mfromstring(\u001b[43moutput\u001b[49m)\n\u001b[1;32m      4\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m child \u001b[38;5;129;01min\u001b[39;00m root:\n\u001b[1;32m      5\u001b[0m     \u001b[38;5;28mprint\u001b[39m(child\u001b[38;5;241m.\u001b[39mtag, child\u001b[38;5;241m.\u001b[39mattrib)\n",
      "\u001b[0;31mNameError\u001b[0m: name 'output' is not defined"
     ]
    }
   ],
   "source": [
    "import xml.etree.ElementTree as et\n",
    "\n",
    "root = et.fromstring(output)\n",
    "for child in root:\n",
    "    print(child.tag, child.attrib)\n",
    "    if child.tag == 'interface':\n",
    "        for subchild in child:\n",
    "            print(' -- ', subchild.tag, subchild.attrib)\n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
